export const useCollapseState = () => {
  // 折叠状态存储
  const collapseStates = ref<Record<string, boolean>>({})
  
  // 默认折叠状态
  const defaultCollapsed = {
    'basic-info': false,
    'education': false,
    'work-experience': false,
    'projects': false,
    'skills': false,
    'self-evaluation': false
  }
  
  // 初始化折叠状态
  const initCollapseStates = () => {
    collapseStates.value = { ...defaultCollapsed }
  }
  
  // 切换折叠状态
  const toggleCollapse = (sectionId: string) => {
    if (collapseStates.value[sectionId] === undefined) {
      collapseStates.value[sectionId] = defaultCollapsed[sectionId] || false
    }
    collapseStates.value[sectionId] = !collapseStates.value[sectionId]
  }
  
  // 获取折叠状态
  const isCollapsed = (sectionId: string) => {
    return collapseStates.value[sectionId] ?? (defaultCollapsed[sectionId] || false)
  }
  
  // 设置折叠状态
  const setCollapsed = (sectionId: string, collapsed: boolean) => {
    collapseStates.value[sectionId] = collapsed
  }
  
  // 全部展开
  const expandAll = () => {
    Object.keys(defaultCollapsed).forEach(sectionId => {
      collapseStates.value[sectionId] = false
    })
  }
  
  // 全部折叠
  const collapseAll = () => {
    Object.keys(defaultCollapsed).forEach(sectionId => {
      collapseStates.value[sectionId] = true
    })
  }
  
  // 重置到默认状态
  const resetToDefault = () => {
    collapseStates.value = { ...defaultCollapsed }
  }
  
  return {
    collapseStates: readonly(collapseStates),
    initCollapseStates,
    toggleCollapse,
    isCollapsed,
    setCollapsed,
    expandAll,
    collapseAll,
    resetToDefault
  }
}
